<template>
  <div class="project">
    <div class="account">
      <div class="account_title">工程计量款</div>
    </div>
    <!-- 顶部 -->
    <div class="top flexAround">
      <div class="top_content">
        <div class="top_content_title">累计计量次数</div>
        <div class="top_content_content">{{isNull(parseFloat((this.topInfo.calculateTotal)).toFixed(0))}}次</div>
      </div>
      <div class="top_content">
        <div class="top_content_title">累计计量金额（万元）</div>
        <div
          class="top_content_content"
        >{{isNull(parseFloat((this.topInfo.totalPrice)).toFixed(2))}}</div>
      </div>
      <div class="top_content">
        <div class="top_content_title">本年度计量金额（万元）</div>
        <div
          class="top_content_content"
        >{{isNull(parseFloat((this.topInfo.yearTotalPrice)).toFixed(2))}}</div>
      </div>
    </div>

    <!-- 中间内容 -->
    <div class="content">
      <div class="center flexBetween">
        <div class="center_title">计量清单</div>
        <div class="flexBetweenCenter">
          <div style="margin-right:50px">
            <a-radio-group v-model="radioModel" @change="onChange">
              <a-radio-button value="0">全部</a-radio-button>
              <a-radio-button value="1">2021</a-radio-button>
              <a-radio-button value="2">2020</a-radio-button>
            </a-radio-group>
          </div>
          <div>
            <a-input-search
              placeholder="请输入姓名查询"
              v-model="fullName"
              style="width: 300px"
              @search="onSearch"
            />
          </div>
        </div>
      </div>
      <div class="atable">
      
        <!-- 表格选中多少项 -->
        <div style="margin-bottom:20px">
          <a-alert type="info">
            <p slot="description">
              <a-icon type="exclamation-circle" style="color:#1890FF;margin-right:5px" />已选择
              <span style="color:#1890FF;margin:0 5px">{{this.selectedRowKeys.length}}</span>项
              <span style="margin-left:10px">计量金额小计：</span>
              <span style="font-weight:600;color:#000">{{selectTotal}}</span> 元
              <span style="color:#1890FF;margin:0 5px;cursor: pointer;" @click="empty">清空</span>
            </p>
          </a-alert>
        </div>
        <a-table
          :columns="columns"
          :data-source="data"
          :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          :pagination="false"
        >
          <span slot="personFinishTotal" slot-scope="text,record">
            <a @click="listModal(record)">附件（{{record.fileList.length}}）</a>
            <!-- {{record}} -->
          </span>
          <!-- <span slot="action" slot-scope="text, record">
            <a style="color:#1890FF;margin-right:10px" @click="onEdit(text, record)">编辑</a>
            <a style="color:#1890FF;margin-right:10px" @click="onDelete(text, record)">删除</a>
          </span> -->
        </a-table>
      </div>
    </div>

    <!-- 分页 -->
    <div class="pagination flexBetween">
      <div> 共{{total}} 条记录 第 {{current}} / {{this.configFun.pageNum(Math.ceil((total/pageSize)))}} 页</div>
      <div>
        <a-pagination
          :current="current"
          :page-size-options="pageSizeOptions"
          :total="this.configFun.pageNum(this.total)"
          show-size-changer
          show-quick-jumper
          :page-size="pageSize"
          @change="pageChange"
          @showSizeChange="onShowSizeChange"
        >
          <template slot="buildOptionText" slot-scope="props">
            <span>{{ props.value }}条/页</span>
            <!-- <span v-if="props.value === '40'">全部</span> -->
          </template>
        </a-pagination>
      </div>
    </div>
    <!-- 附件列表对话框 -->
    <div class="amodal">
      <a-modal
        v-model="visibleList"
        title="计量凭证附件"
        :maskClosable="false"
        cancelText="取消"
        okText="确认"
        :centered="true"
        :footer="null"
      >
        <div style="height:200px">
          <div v-for="(item,index) in pdfList" :key="index" @click="pdfShow(item.fileUrl)">
            <span style="color:#1890ff;cursor:pointer">{{item.fileName}}</span>
          </div>
        </div>
      </a-modal>
    </div>
    <!-- pdf对话框 -->
    <div>
      <a-modal
        v-model="visiblePdf"
        :centered="true"
        :footer="null"
        :maskClosable="false"
        width="1080px"
        :bodyStyle="{textAlign:'center'}"
        v-if="visiblePdf"
        key="modal2"
        class="pdfModal"
      >
        <embed v-if="visiblePdf" width="1000" height="700" :src="this.pdfUrl" type />
      </a-modal>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { calculateQuery } from '@/api/measurementManage'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      radioModel: '0',
      columns: [
        { title: '名称', dataIndex: 'name', key: 'name', align: 'center' },
        { title: '计量金额（元）', dataIndex: 'calculatePrice', key: 'calculatePrice', align: 'center' },
        { title: '计量日期', dataIndex: 'calculateDate', key: 'calculateDate', align: 'center' },
        {
          title: '计量凭证',
          dataIndex: 'personFinishTotal',
          key: 'personFinishTotal',
          align: 'center',
          scopedSlots: { customRender: 'personFinishTotal' }
        },

        // {
        //   title: '操作',
        //   key: 'action',
        //   scopedSlots: { customRender: 'action' },
        //   align: 'center'
        // }
      ],
      data: [],
      current: 1,
      modelTitle: '新建计量',
      pageSize: 10,
      isUpload: false,
      total: 1,
      spinning: false,
      pageSizeOptions: ['5', '10', '20', '30', '40'],
      visible: false,
      visibleList: false,
      visiblePdf: false,
      form: {
        fileInfoList: [],
        calculatePrice: '',
        calculateDate: null,
        packageId: '',
        name: ''
      },
      pdfList: [],
      explain: '',
      selectedRowKeys: [],

      labelCol: { span: 7 },
      wrapperCol: { span: 12 },
      selectTotal: 0,
      textSize: { minRows: 3, maxRows: 6 },
      topData: {},
      yearData: '',
      fullName: '',
      topInfo: {},
      editId: '',
      editPackageId: '',
      pdfUrl: '',
     
    }
  },
  mounted() {
    this.getData()
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    // 搜索
    onSearch() {
      this.getData()
    },
    // 点击附件
    listModal(record) {
      // console.log(record);

      this.pdfList = record.fileList
      this.visibleList = true
    },
    pdfShow(url) {
      this.pdfUrl = url
      this.visiblePdf = true
    },
    // 表格
    getData() {
      let data = {
        page: this.current,
        size: this.pageSize,
        calculateDate: this.yearData,
        likeName: this.fullName,
        orgId: sessionStorage.getItem('gatewayId')
      }
      this.data = []
      calculateQuery(data).then((res) => {
        // this.topData.personTotal = res.data.data.personTotal
        // this.topData.recordTotal = res.data.data.recordTotal
        // this.topData.wageTotal = res.data.data.wageTotal
        // console.log(res.data);

        this.topInfo = res.data.data
        res.data.data.calculateVOList.forEach((item, index) => {
          item.key = item.id
        })
        this.data = res.data.data.calculateVOList
        this.total = res.data.data.total
      })
    },
    // 判断isNaN
    isNull(val) {
      if (isNaN(val) == true) {
        return 0
      } else {
        return val
      }
    },
    moment,
    // 切换选项卡
    onChange(e) {
      // console.log(this.radioModel)
      this.current = 1
      this.pageSize = 10
      switch (e.target.value) {
        case '0':
          this.yearData = ''

          this.empty()
          break
        case '1':
          this.yearData = '2021'
          this.empty()
          break
        case '2':
          this.yearData = '2020'
          this.empty()
          break
        default:
          break
      }
      this.getData()
    },
    onShowSizeChange(current, pageSize) {
      // console.log(current, pageSize)
      this.current = 1
      this.pageSize = pageSize
      this.getData()
    },
    pageChange(current, pageSize) {
      this.current = current
      this.pageSize = pageSize
      this.getData()
    },
    // 勾选
    onSelectChange(selectedRowKeys) {
      // console.log('selectedRowKeys changed: ', selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys
      // console.log( this.selectedRowKeys);
      this.selectTotal = 0
      let _this = this

      this.selectedRowKeys.forEach((item, index) => {
        // let key = item
        // console.log(key,index);
        let total = 0
        this.data.forEach((res) => {
          if (item == res.key) {
            total = res.calculatePrice
          }
        })
        // console.log(_this.data[index]);
        this.selectTotal = this.selectTotal + (total - 0)
        this.selectTotal = parseFloat(this.selectTotal.toFixed(2))
      })
    },
    // 清空
    empty() {
      // console.log(11);

      this.selectedRowKeys = []
      this.selectTotal = 0
    }
  }
}
</script>

<style scoped>
.flexAround {
  width: 100%;
}
.atable {
  width: 100%;
}
.top {
  text-align: center;
  color: #555;
  margin-bottom: 20px;
  background: #fff;
  padding: 15px 30px;
}
.center {
  margin-bottom: 20px;
}
.content {
  background: #fff;
  padding: 15px 0px;
  margin-bottom: 15px;
  width: 100%;
}
.top_content {
  flex: 1;
  border-right: 1px solid #ccc;
}
.top_content:last-of-type {
  border: none;
}
.top_content_content {
  color: #000;
  font-size: 30px;
  /* font-weight: 600; */
}
.center_title {
  font-size: 16px;
  color: #000;
  font-weight: 600;
}
::v-deep .ant-alert-with-description .ant-alert-message {
  margin-bottom: 0;
}
::v-deep .ant-alert-with-description.ant-alert-no-icon {
  padding: 4px;
}
p {
  margin: 0;
  padding-left: 20px;
}
.delete:hover {
  color: #1890ff;
  cursor: pointer;
}
.pdfList {
  padding: 5px 10px;
  border: 1px solid #ccc;
  margin: 7px 0px;
}
::v-deep .ant-upload.ant-upload-select {
  width: 100%;
}
::v-deep .ant-modal {
  padding-bottom: 0;
}
.account {
  height: 45px;
  /* border-bottom: 1px solid #ccc; */
  margin-bottom: 30px;
}
.account_title {
  width: 90px;
  height: 45px;
  font-size: 16px;
  line-height: 45px;
  color: #1890ff;
  border-bottom: 2px solid #1890ff;
  text-align: center;
  margin-left: 30px;
}
</style>
